package io.shallwe.scanner.auto;

import org.tio.core.ChannelContext;
import org.tio.core.intf.Packet;
import org.tio.server.intf.ServerAioListener;

import com.jfinal.kit.LogKit;

/**
 *   自动扫描枪状态监听
 * @author 王小伟
 * @date 2016-06-16 00:21:11
 */

public class AutoScannerListener implements ServerAioListener{

	@Override
	public void onAfterConnected(ChannelContext channelContext, boolean isConnected, boolean isReconnect)
			throws Exception {
		String ip = channelContext.getClientNode().getIp();
		if(isConnected) {
			switch(ip) {
			case "172.30.31.52":
				LogKit.warn("连接上线自动扫描枪成功");
				break;
			case "172.30.31.53":
				LogKit.warn("连接下线自动扫描枪成功");
				break;
				default:
					break;
			}
			
		}else {
			
		}
	}

	@Override
	public void onAfterDecoded(ChannelContext channelContext, Packet packet, int packetSize) throws Exception {
		
	}

	@Override
	public void onAfterReceivedBytes(ChannelContext channelContext, int receivedBytes) throws Exception {
		
	}

	@Override
	public void onAfterSent(ChannelContext channelContext, Packet packet, boolean isSentSuccess) throws Exception {
		
	}

	@Override
	public void onAfterHandled(ChannelContext channelContext, Packet packet, long cost) throws Exception {
		
	}

	@Override
	public void onBeforeClose(ChannelContext channelContext, Throwable throwable, String remark, boolean isRemove)
			throws Exception {
		String ip = channelContext.getClientNode().getIp();
			switch(ip) {
			case "172.30.31.52":
				LogKit.warn("上线自动扫描枪关闭连接");
				break;
			case "172.30.31.53":
				LogKit.warn("下线自动扫描枪关闭连接");
				break;
				default:
					break;
			}
			
	}

	@Override
	public boolean onHeartbeatTimeout(ChannelContext channelContext, Long aLong, int i) {
		return false;
	}
}
